package main

import (
	"crypto/tls"
	"fmt"
	"io/ioutil"
	"net/http"
	"time"
)

func FetchCommonGet(url string, header map[string]string, reqData map[string]string) (res []byte, err error) {
	var req *http.Request
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		DisableKeepAlives: true,
	}
	client := http.Client{
		Transport: tr,
		Timeout: time.Duration(5)*time.Second,
	}
	defer client.CloseIdleConnections()

	if req, err = http.NewRequest(http.MethodGet, url, nil); err != nil {
		panic(err)
	}
	for k, v := range header {
		req.Header.Add(k, v)
	}
	resp, err := client.Do(req)

	if err != nil {
		return
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		err = fmt.Errorf("    wrong status code %d", resp.StatusCode)
		return
	}
	res, err = ioutil.ReadAll(resp.Body)
	return
}
